package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.AgricultureGroom;
import com.isunland.managesystem.ui.AgricultureGroomListFragment;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/4/5 15:55
 */
public class AgricultureGroomListAdapter<T> extends BaseAdapter {
  private ArrayList<T> objects = new ArrayList<>();
  private LayoutInflater layoutInflater;
  private String groomtype;

  public AgricultureGroomListAdapter(Context context, ArrayList<T> objects, String groomtype) {
    this.layoutInflater = LayoutInflater.from(context);
    this.objects = objects;
    this.groomtype = groomtype;
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      //convertView = layoutInflater.inflate(R.layout.adapter_locale_work_query_count, parent, false);
      convertView = layoutInflater.inflate(R.layout.adapter_customer_back, parent, false);
      convertView.setTag(new ViewHolder(convertView));
    }
    initializeViews(getItem(position), (ViewHolder) convertView.getTag());
    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder) {
    AgricultureGroom item = (AgricultureGroom) object;

    holder.tvTitle.setText(item.getGroomtype());
    if (AgricultureGroomListFragment.AGRICULTURAL_PRODUCTION.equalsIgnoreCase(groomtype)) {
      holder.ivLogo.setImageResource(R.drawable.nongzijiaoyi);
    }
    if (AgricultureGroomListFragment.AGRICULTURAL_VISIT.equalsIgnoreCase(groomtype)) {
      holder.ivLogo.setImageResource(R.drawable.guanguangnongyerenyang);
    }

    holder.tvContent.setText(item.getGroomplatform());
    holder.tvBottom.setText(
        MyStringUtil.connect(item.getRegStaffName(), MyStringUtil.SEPEREATE, item.getRegDate()));
  }

  static class ViewHolder {
    @BindView(R.id.iv_logo) ImageView ivLogo;
    @BindView(R.id.tv_title) TextView tvTitle;
    @BindView(R.id.tv_status) TextView tvStatus;
    @BindView(R.id.tv_content) TextView tvContent;
    @BindView(R.id.tv_bottom) TextView tvBottom;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}

